package com.example.asapp.demo.test;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

import javax.jms.Destination;
import javax.jms.Queue;
import javax.jms.Topic;

@Service
@Slf4j
@EnableAsync
public class AsyncTaskService {
    //表明该方法是异步方法，如果注解在类上，则表明该类的所有方法都是异步方法，
    //这里的方法自动被注入使用ThreadPoolTaskExecutor作为TaskExecutor

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private Queue queue;

    @Autowired
    private Topic topic;

    static int m=0;
    @Async
    public void sendToQueue(Object payload){
        log.info("id is {}",(String)payload);
//        jmsMessagingTemplate.convertAndSend(this.queue,payload);
    }

    @Async
    public void sendToTopic(Object payload){
        jmsMessagingTemplate.convertAndSend(this.topic,payload);
    }
}
